<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app {
            display: flex;
            flex-direction: column;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
        }

        .menu-list {
            list-style: none;
            padding: 0;
            margin: 0;
            width: 100%;
            height: 40px;
            display: flex;
            justify-content: space-between;
            line-height: 40px;
            font-size: 16px;
            color: #333;
        }

        .menu-list li {
            flex: 1;
            text-align: center;
            line-height: 40px;
        }

        .menu-list li a {
            text-decoration: none;
            color: #333;
        }

        .menu-list li.active {
            background: rgb(237, 220, 215);
        }

        .menu-list li.active a {
            color: red;
        }

        .content {
            flex: 1;
        }

        .goods-container {
            display: flex;
            justify-content: space-between;
            width: 100%;
            height: 100%;
        }

        .goods-container .container-menu {
            width: 120px;
            height: 100%;
            background: #ddd;
            border: 1px solid #ddd;
            box-sizing: border-box;
        }

        .goods-container .container-menu .menu-item {
            width: 120px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            background-color: #fff;
        }

        .goods-container .container-menu .menu-item.active {
            background: #ddd;
        }

        .goods-container .container-detail {
            flex: 1;
        }

        .footer {
            /* flex: 1; */
            width: 100%;
            height: 40px;
            background: rgb(25, 35, 43);
            text-align: center;
            line-height: 40px;
            color: #ffff;
        }
    </style>
</head>
<body>
<div id="app">
    <!-- 点击菜单栏的按钮，跳转到相应的路由组件 -->
    <ul class="menu-list">
        <li :class="{active: $route.path === '/goods'}">
            <router-link to="/goods">商品</router-link>
        </li>
        <li :class="{active: $route.path === '/evaluate'}">
            <router-link to="/evaluate">评价</router-link>
        </li>
        <li :class="{active: $route.path === '/shangjia'}">
            <router-link to="/shangjia">商家</router-link>
        </li>
    </ul>

    <!-- 路由渲染器 -->
    <div class="content">
        <router-view></router-view>
    </div>

    <div class="footer">
        共￥202
    </div>
</div>

<script src="./data.js"></script>
<script src="../20211018/vue.js"></script>
<!-- 路由 -->
<script src="../vue-router.js"></script>
<script>
    // console.log(data)
    // 路由传参
    let comGoods = {
        template: `
            <div class="goods-container">
                <div class="container-menu">
                    <div v-for="(item, index) in menuData" @click="getChildren(item)" class="menu-item">{{item.title}}</div>    
                </div>
                <div class="container-detail">
                    <div v-for="(item, index) in menuChildren">
                        {{item.subTitle}}
                        {{item.remark}}
                        {{item.price}}
                    </div>
                </div>
            </div>
        `,
        data () {
            return {
                // menuData: [],
                menuChildren: []
            }
        },
        methods: {
            getChildren (item) {
                console.log(item)
                this.menuChildren = item.children
            }
        },
        // mounted () {
        //     this.menuData = data
        // },
        computed: {
            menuData () {
                return data
            }
        }
    }
    let comEvaluate = {
        template: `<div>这是评价页面</div>`
    }
    let comShangjia = {
        template: `<div>这是商家页面</div>`
    }

    // 创建路由实例
    let router = new VueRouter({
        // 路由列表
        routes: [
            {path: '/goods', component: comGoods},
            {path: '/evaluate', component: comEvaluate},
            {path: '/shangjia', component: comShangjia}
        ]
    })

    let myApp = new Vue({
        el: '#app',
        router,
        data: {
        },
        methods: {
            toPath () {
                console.log(this.$route)
            }
        }
    })
</script>
</body>
</html>